﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pb;
using System.Linq;
using UnityEngine.SceneManagement;


public class XTJGame100 : Game
{
    public GameObject Root;
    EginUser user = EginUser.Instance;
    EginXTJ xtj = EginXTJ.Instance;
    private int uid;

    public List<XTJUser> xtjUsers;
    public XTJMyOwnInfo xtjMyOwnInfo;
    public XTJBankerInfo xtjBankerInfo;

    public UILabel playersNum;//房间中玩家的数量

    public GameObject exitBtn;
    public GameObject MoneyBtn;
    public GameObject SetBtn;
    //public GameObject readyBtn;
    //public GameObject QiangZhuang;
    public GameObject bankerUpBtn;
    public GameObject bankerDownBtn;
    public GameObject playersBtn;
    public GameObject historyBtn;
    public GameObject chatBtn;

    public GameObject SetSaizi;//进行掷骰子操作

    #region 押注
    public GameObject ShunMen;
    public GameObject ShunJiao;
    public GameObject Tang;
    public GameObject Tianmen;
    public GameObject Daomen;
    public GameObject Daojiao;
    #endregion
    public long betCoinCount;//下注金币
    public int Direction;//下注方位
    //某个方位的总的筹码数显示框
    public List<UILabel> poolChipsCountLabels;
    //某个方位的自己下的筹码数显示框
    public List<UILabel> ownChipsCountLabels;
    //public List<long> poolChipsCountList;
    public List<long> ownChipsCountList;
    public GameObject stopBet;

    public GameObject ChipPre;//下注的筹码预制体；
    public GameObject cardsPre;//发的牌的预设
    //发牌位置
    public Dictionary<int, GameObject> dealCardsPosDic = new Dictionary<int, GameObject>();
    //所发的牌
    public Dictionary<int, GameObject> dealCardsDic = new Dictionary<int, GameObject>();

    //所掷点数之和
    public int diceSum;
    public GameObject chipParent;//筹码父物体  
    //音效
    public List<AudioClip> effectBgList;

    public GameObject chatItem;
    public UILabel text;
    public UISprite face;
    public UISprite chatAvatar;
    private GameObject bankPanel;
    private BankModel bankModel;
    public UILabel coinCount;
    public int isHaveCoin;

    private string[] xtjText = {
        "大家好，很高兴见到各位！",
        "玩就玩大的，不要怂！！",
        "跟着我下，稳赚不赔！",
        "我就呵呵了！",
        "我要坐庄，都别跟我抢！",
        "发牌就抢庄，赢牌心不慌！",
        "不要走决战到天亮！"
    };


    // Use this for initialization
    void Awake()
    {
        UIEventListener.Get(exitBtn).onClick = ButtonOnclick;
        UIEventListener.Get(MoneyBtn).onClick = ButtonOnclick;
        UIEventListener.Get(SetBtn).onClick = ButtonOnclick;
        //UIEventListener.Get(readyBtn).onClick = ButtonOnclick;
        //UIEventListener.Get(QiangZhuang).onClick = ButtonOnclick;
        UIEventListener.Get(bankerDownBtn).onClick = ButtonOnclick;
        UIEventListener.Get(bankerUpBtn).onClick = ButtonOnclick;
        UIEventListener.Get(playersBtn).onClick = ButtonOnclick;
        UIEventListener.Get(historyBtn).onClick = ButtonOnclick;
        UIEventListener.Get(chatBtn).onClick = ButtonOnclick;

        UIEventListener.Get(ShunMen).onClick = ButtonOnclick;
        UIEventListener.Get(ShunJiao).onClick = ButtonOnclick;
        UIEventListener.Get(Tang).onClick = ButtonOnclick;
        UIEventListener.Get(Tianmen).onClick = ButtonOnclick;
        UIEventListener.Get(Daomen).onClick = ButtonOnclick;
        UIEventListener.Get(Daojiao).onClick = ButtonOnclick;
    }
    void Start()
    {
        uid = int.Parse(user.Uid);
        LoadUser();//加载玩家信息
        base.StartGameSocket();
        SocketManager.Instance.socketListener = this;
        xtj.currentChip = xtj.chipList[0];


    }
    void ButtonOnclick(GameObject Btn)
    {
        if (Btn.name == "ExitBtn")
        {
            PaiLeaveRoundRequest message = new PaiLeaveRoundRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiLeaveRoundRequest);
        }
        else if (Btn.name == "Money")
        {
            //银行
            bankPanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.Bank));
            bankModel = bankPanel.GetComponent<BankModel>();
            bankModel.sumLabel.text = "已存入:" + user.bankCoinCount + "万金币";
            //Add_MoneyModel addMoneyModel = AddMoney.GetComponent<Add_MoneyModel>();
            //addMoneyModel.PayForGold.SetActive(true);
            //addMoneyModel.PayForRoomCard.SetActive(false);
            //addMoneyModel.TransferAccount.SetActive(false);
            //addMoneyModel.GoldBtnBg.SetActive(true);
            //addMoneyModel.RoomCardBtnBg.SetActive(false);
            //addMoneyModel.TransfBtnBg.SetActive(false);
        }
        else if (Btn.name == "SetBtn")
        {
            NGUITools.AddChild(this.gameObject, (GameObject)(Resources.Load(GameXTJPrafabPath.XTJSetPanel)));
        }
        else if (Btn.name == "ReadyBtn")
        {
            //向服务器发送准备信息
            //readyBtn.SetActive(false);
            PaiRoundReadyRequest message = new PaiRoundReadyRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiRoundReadyRequest);
        }
        else if (Btn.name == "QiangZhuangBtn")
        {
            //抢庄请求
            //QiangZhuang.SetActive(false);
            PaiGrabMasterRequest message = new PaiGrabMasterRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiGrabMasterRequest);
        }
        else if (Btn.name == "BankerUpBtn")
        {
            //抢庄请求
            bankerUpBtn.SetActive(false);
            PaiGrabMasterRequest message = new PaiGrabMasterRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiGrabMasterRequest);
        }
        else if (Btn.name == "BankerDownBtn")
        {
            bankerDownBtn.SetActive(false);
            PaiGiveUpMasterRequest message = new PaiGiveUpMasterRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiGiveUpMasterRequest);
        }
        else if (Btn.name == "HistoryBtn")
        {
            PaiCardHistoryRequest message = new PaiCardHistoryRequest { RoundId = xtj.roundId };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiCardHistoryRequest);
        }
        else if (Btn.name == "PlayersBtn")
        {
            PaiAllPlayersRequest message = new PaiAllPlayersRequest { RoundId = xtj.roundId, Page = 1 };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiAllPlayersRequest);
        }
        else if (Btn.name == "ChatBtn")
        {
            GameObject chat = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.chat));
        }
        else if (Btn.name == "setSaizi")//掷骰子请求操作
        {
            SetSaizi.SetActive(false);
            PaiThrowDiceRequest message = new PaiThrowDiceRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(message, MsgId.PaiThrowDiceRequest);
        }
        else if (Btn.name == "ShunMen")
        {
            Direction = 1;
            ownChipsCountList[0] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }
        else if (Btn.name == "Tang")
        {
            Direction = 2;
            ownChipsCountList[1] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }
        else if (Btn.name == "Daomen")
        {
            Direction = 3;
            ownChipsCountList[2] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }
        else if (Btn.name == "Daojiao")
        {
            Direction = 4;
            ownChipsCountList[3] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }
        else if (Btn.name == "Tianmen")
        {
            Direction = 5;
            ownChipsCountList[4] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }
        else if (Btn.name == "ShunJiao")
        {
            Direction = 6;
            ownChipsCountList[5] += xtj.currentChip;
            PaiBetRequest(xtj.currentChip, Direction);
        }

    }
    void PaiBetRequest(long coin, int dir)
    {
        Debug.Log("下注请求,下注金币是：" + coin + ",下注方位是：" + dir);
        PaiBetRequest message = new PaiBetRequest { Coin = coin, Direction = dir };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(message, MsgId.PaiBetRequest);
    }

    public override void SocketReceiveMessage(byte[] data)
    {
        base.SocketReceiveMessage(data);
        byte[] dataLength = data.Skip(0).Take(2).ToArray();
        byte[] dataId = data.Skip(2).Take(4).ToArray();
        byte[] dataConcent = data.Skip(data.Length - (data.Length - 4)).ToArray();
        int TempMsgID = ProtoDataToMsg.Byte2ushort(dataId);
        #region  加入房间
        //加入房间
        if (TempMsgID == MsgId.PaiEnterRoundBroadcast)
        {
            Pb.PaiEnterRoundBroadcast newpb = Pb.PaiEnterRoundBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log("有玩家加入房间了");
            //if (newpb.Status == (int)STATUS.Success)
            {
                //显示房间中的人数
                playersNum.text = newpb.Round.OnlineNumber.ToString();
                if (xtj.playersList.Count < 4)
                {
                    xtj.playersList.Add(newpb.Round.NewPlayer);
                }

                //重新显示座上玩家的信息
                for (int i = 0; i < xtj.playersList.Count; i++)
                {
                    xtjUsers[i].goldLabel.text = user.ReturnMoneyForLong(xtj.playersList[i].Coin);
                    xtjUsers[i].goldLabel.transform.parent.gameObject.SetActive(true);
                    xtjUsers[i].chairLabel.gameObject.SetActive(false);
                    xtjUsers[i].uid = xtj.playersList[i].Id;
                    if (xtj.playersList[i].AvatarUrl != "")
                    {
                        WXAvatarManager._instance.GetWxAvatar(xtj.playersList[i].Id, xtjUsers[i].wxAvatar, xtj.playersList[i].AvatarUrl);
                        xtjUsers[i].wxAvatar.gameObject.SetActive(true);
                    }
                    else
                    {
                        xtjUsers[i].avatar.spriteName = xtj.playersList[i].AvatarId.ToString();
                        xtjUsers[i].avatar.gameObject.SetActive(true);
                    }
                }

                //显示庄家的信息
                if (newpb.Round.MasterInfo.Id != 0)
                {
                    xtjBankerInfo.nameLabel.text = newpb.Round.MasterInfo.Nickname;
                    xtjBankerInfo.goldLabel.text = user.ReturnMoneyForLong(newpb.Round.MasterInfo.Coin);
                    xtjBankerInfo.uid = newpb.Round.MasterInfo.Id;
                    xtj.bankerInfo = newpb.Round.MasterInfo;
                    if (xtj.bankerInfo.AvatarUrl != "")
                    {
                        WXAvatarManager._instance.GetWxAvatar(xtj.bankerId, xtjBankerInfo.wxAvatar, xtj.bankerInfo.AvatarUrl);
                        xtjBankerInfo.wxAvatar.gameObject.SetActive(true);
                    }
                    else
                    {
                        xtjBankerInfo.avatar.spriteName = xtj.bankerInfo.AvatarId.ToString();
                    }
                }
                else
                {
                    xtjBankerInfo.nameLabel.text = "系统坐庄";
                    xtjBankerInfo.avatar.spriteName = "avatar";
                }
                xtjBankerInfo.gameObject.SetActive(true);
            }
        }
        #endregion 加入房间
        #region 自己离开房间响应
        //自己离开房间
        else if (TempMsgID == MsgId.PaiLeaveRoundResponse)
        {
            Pb.PaiLeaveRoundResponse newpb = Pb.PaiLeaveRoundResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == (int)STATUS.Success)
            {
                xtj.playersList.Clear();
                //if(uid == xtj.bankerId){
                //    xtj.bankerId = 0;
                //}               
                //for (int i = 0; i < xtjUsers.Count; i++)
                //{
                //    xtjUsers[i].InitPlayer();
                //}
                SceneManager.LoadSceneAsync(ScenePath.Hall);

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject msg = NGUITools.AddChild(Root, (GameObject)Resources.Load("LogMsg"));
            }
        }
        #endregion 自己离开房间响应

        #region 其他玩家离开房间
        //其他玩家离开房间
        else if (TempMsgID == MsgId.PaiLeaveRoundBroadcast)
        {
            Pb.PaiLeaveRoundBroadcast newpb = Pb.PaiLeaveRoundBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log("有玩家离开房间了");
            xtj.playersList = newpb.PlayerInfo.ToList();
            for (int i = 0; i < newpb.PlayerInfo.Count; i++)
            {
                if (uid != newpb.PlayerInfo[i].Id)
                {
                    xtjUsers[i].goldLabel.text = user.ReturnMoneyForLong(newpb.PlayerInfo[i].Coin);
                    xtjUsers[i].goldLabel.transform.parent.gameObject.SetActive(true);
                    xtjUsers[i].chairLabel.gameObject.SetActive(false);
                    xtjUsers[i].uid = newpb.PlayerInfo[i].Id;
                    if (xtj.playersList[i].AvatarUrl != "")
                    {
                        WXAvatarManager._instance.GetWxAvatar(xtj.playersList[i].Id, xtjUsers[i].wxAvatar, xtj.playersList[i].AvatarUrl);
                        xtjUsers[i].wxAvatar.gameObject.SetActive(true);
                    }
                    else
                    {
                        xtjUsers[i].avatar.spriteName = xtj.playersList[i].AvatarId.ToString();
                        xtjUsers[i].avatar.gameObject.SetActive(true);
                    }
                }
            }
            for (int i = 0; i < xtjUsers.Count; i++)
            {
                if (newpb.PlayerId == xtjUsers[i].uid)
                {
                    xtjUsers[i].uid = 0;
                    xtjUsers[i].chairLabel.gameObject.SetActive(true);
                    xtjUsers[i].goldLabel.transform.parent.gameObject.SetActive(false);
                    xtjUsers[i].avatar.gameObject.SetActive(false);
                    xtjUsers[i].wxAvatar.gameObject.SetActive(false);
                }
            }

            //更新房间中的人数
            playersNum.text = newpb.OnlineNumber.ToString();

        }
        #endregion 其他玩家离开房间

        #region 玩家被踢出房间的广播
        else if (TempMsgID == MsgId.PaiKickOutRoundBroadcast)//被踢出去的玩家的广播
        {
            Pb.PaiKickOutRoundBroadcast newpb = Pb.PaiKickOutRoundBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log(user.Uid);
            //自己被踢出房间
            if (newpb.PlayerId == uid)
            {
                //user.zhunbei = false;
                xtj.playersList.Clear();
                SceneManager.LoadSceneAsync(ScenePath.Hall);
            }
            //其他人被踢出房间
            else
            {
                //被踢出的是座上的玩家
                for (int i = 0; i < xtj.playersList.Count; i++)
                {
                    if (newpb.PlayerId == xtjUsers[i].uid)
                    {
                        xtjUsers[i].InitPlayer100();
                    }
                }
                //被踢出的是庄家
                if (newpb.PlayerId == xtj.bankerId)
                {
                    xtjBankerInfo.wxAvatar.gameObject.SetActive(false);
                    xtjBankerInfo.gameObject.SetActive(false);
                }
            }

        }
        #endregion 玩家被踢出房间的广播

        #region 通知玩家开始准备
        else if (TempMsgID == MsgId.PaiRoundReadyBroadcast)//通知玩家开始准备
        {
            Pb.PaiRoundReadyBroadcast newpb = Pb.PaiRoundReadyBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.BetTime));
            //播放开始游戏音效
            SoundModel.PlaySound(effectBgList[4]);
        }
        #endregion 通知玩家开始准备

        #region  通知开始抢庄广播
        else if (TempMsgID == MsgId.PaiGrabMasterBroadcast)//开始抢庄
        {
            Pb.PaiGrabMasterBroadcast newpb = Pb.PaiGrabMasterBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log("开始抢庄");

            bankerUpBtn.SetActive(true);


        }
        #endregion  通知开始抢庄广播

        #region  开始抢庄响应
        //抢庄响应
        else if (TempMsgID == MsgId.PaiGrabMasterResponse)
        {
            Pb.PaiGrabMasterResponse newpb = Pb.PaiGrabMasterResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == (int)STATUS.Success)
            {

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject msg = NGUITools.AddChild(Root, (GameObject)Resources.Load("LogMsg"));
            }
        }
        #endregion  开始抢庄响应
        #region  抢庄结果广播
        else if (TempMsgID == MsgId.PaiGrabMasterResultBroadcast)//抢庄结果信息
        {
            Pb.PaiGrabMasterResultBroadcast newpb = Pb.PaiGrabMasterResultBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //QiangZhuang.SetActive(false);
            xtj.bankerId = newpb.PlayerId;
            //显示庄家的信息
            if (newpb.PlayerId != 0)
            {
                xtjBankerInfo.nameLabel.text = newpb.Name;
                xtjBankerInfo.goldLabel.text = user.ReturnMoneyForLong(newpb.Coin);
                xtjBankerInfo.uid = newpb.PlayerId;
                xtj.bankerId = newpb.PlayerId;
                if (newpb.AvatarUrl != "")
                {
                    WXAvatarManager._instance.GetWxAvatar(newpb.PlayerId, xtjBankerInfo.wxAvatar, newpb.AvatarUrl);
                    xtjBankerInfo.wxAvatar.gameObject.SetActive(true);
                }
                else
                {
                    xtjBankerInfo.avatar.spriteName = newpb.AvatarId.ToString();
                }

                bankerDownBtn.SetActive(false);
                bankerUpBtn.SetActive(false);

            }
            else
            {
                xtjBankerInfo.nameLabel.text = "系统坐庄";
                xtjBankerInfo.avatar.spriteName = "avatar";
                xtjBankerInfo.goldLabel.text = user.ReturnMoneyForLong(newpb.Coin);
                xtjBankerInfo.uid = 0;
            }
            xtjBankerInfo.gameObject.SetActive(true);
            //StartCoroutine(QiangBanker(xtj.grabMasterList, newpb.PlayerId));

        }
        #endregion  抢庄结果广播

        #region  放弃坐庄广播
        else if (TempMsgID == MsgId.PaiGiveUpMasterBroadcast)
        {
            bankerDownBtn.SetActive(true);
        }
        #endregion  放弃坐庄广播

        #region  开始下注广播
        else if (TempMsgID == MsgId.PaiBetBroadcast)//开始进行下注操作
        {
            Pb.PaiBetResultBroadcast newpb = Pb.PaiBetResultBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //播放开始下注音效
            SoundModel.PlaySound(effectBgList[0]);
            //QiangZhuang.SetActive(false);
            Debug.Log("执行开始下注操作");
            //加载下注时间
            GameObject betTime = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.BetTime));
            betTime.transform.localPosition = new Vector3(-35, 8, 0);
            bankerDownBtn.SetActive(false);
            bankerUpBtn.SetActive(false);
        }
        #endregion  开始下注广播

        #region  下注响应
        //下注响应
        else if (TempMsgID == MsgId.PaiBetResponse)
        {
            Pb.PaiBetResponse newpb = Pb.PaiBetResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == (int)STATUS.Success)
            {

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject msg = NGUITools.AddChild(Root, (GameObject)Resources.Load("LogMsg"));
            }
        }
        #endregion  下注响应

        #region  下注广播
        else if (TempMsgID == MsgId.PaiBetResultBroadcast)//有玩家进行下注操作
        {
            Pb.PaiBetResultBroadcast newpb = Pb.PaiBetResultBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //if (newpb.Status == (int)STATUS.Success)
            {
                //播放加注音效
                SoundModel.PlaySound(effectBgList[1]);
                //克隆筹码
                CloneChips(newpb.PlayerId, newpb.Direction, newpb.Coin);

                //显示各个位置的总筹码数
                foreach (KeyValuePair<int, long> keyValue in newpb.AllPlayerCoinMap)
                {
                    if (keyValue.Key == 1)
                    {
                        poolChipsCountLabels[0].text = newpb.AllPlayerCoinMap[1].ToString();
                    }
                    else if (keyValue.Key == 2)
                    {
                        poolChipsCountLabels[1].text = newpb.AllPlayerCoinMap[2].ToString();
                    }
                    else if (keyValue.Key == 3)
                    {
                        poolChipsCountLabels[2].text = newpb.AllPlayerCoinMap[3].ToString();
                    }
                    else if (keyValue.Key == 4)
                    {
                        poolChipsCountLabels[3].text = newpb.AllPlayerCoinMap[4].ToString();
                    }
                    else if (keyValue.Key == 5)
                    {
                        poolChipsCountLabels[4].text = newpb.AllPlayerCoinMap[5].ToString();
                    }
                    else if (keyValue.Key == 6)
                    {
                        poolChipsCountLabels[5].text = newpb.AllPlayerCoinMap[6].ToString();
                    }
                }
                //显示自己在各个位置所下的筹码数
                if (uid == newpb.PlayerId)
                {
                    foreach (KeyValuePair<int, long> keyValue in newpb.CurrentPlayerCoinMap)
                    {
                        if (keyValue.Key == 1)
                        {
                            ownChipsCountLabels[0].text = newpb.CurrentPlayerCoinMap[1].ToString();
                            //ownChipsCountList[0] += newpb.CurrentPlayerCoinMap[1];
                        }
                        else if (keyValue.Key == 2)
                        {
                            ownChipsCountLabels[1].text = newpb.CurrentPlayerCoinMap[2].ToString();
                            //ownChipsCountList[1] += newpb.CurrentPlayerCoinMap[2];
                        }
                        else if (keyValue.Key == 3)
                        {
                            ownChipsCountLabels[2].text = newpb.CurrentPlayerCoinMap[3].ToString();
                            //ownChipsCountList[2] += newpb.CurrentPlayerCoinMap[3];
                        }
                        else if (keyValue.Key == 4)
                        {
                            ownChipsCountLabels[3].text = newpb.CurrentPlayerCoinMap[4].ToString();
                            //ownChipsCountList[3] += newpb.CurrentPlayerCoinMap[4];
                        }
                        else if (keyValue.Key == 5)
                        {
                            ownChipsCountLabels[4].text = newpb.CurrentPlayerCoinMap[5].ToString();
                            //ownChipsCountList[4] += newpb.CurrentPlayerCoinMap[5];
                        }
                        else if (keyValue.Key == 6)
                        {
                            ownChipsCountLabels[5].text = newpb.CurrentPlayerCoinMap[6].ToString();
                            //ownChipsCountList[5] += newpb.CurrentPlayerCoinMap[6];
                        }
                    }
                }


                //更新玩家金币数                
                if (newpb.PlayerId == uid)
                {
                    xtjMyOwnInfo.goldLabel.text = user.ReturnMoneyForLong(newpb.RestCoin);
                }
                else
                {
                    for (int i = 0; i < xtjUsers.Count; i++)
                    {
                        if (newpb.PlayerId == xtjUsers[i].uid)
                        {
                            xtjUsers[i].goldLabel.text = user.ReturnMoneyForLong(newpb.RestCoin);
                        }
                    }
                }


            }
            //else
            //{
            //    user.logMsg = newpb.Msg;
            //    GameObject msg = NGUITools.AddChild(Root, (GameObject)Resources.Load("LogMsg"));
            //}

        }
        #endregion  下注广播

        #region  停止下注广播
        else if (TempMsgID == MsgId.PaiBetStopBroadcast)//停止押注
        {
            Pb.PaiBetStopBroadcast newpb = Pb.PaiBetStopBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //播放停止下注音效
            SoundModel.PlaySound(effectBgList[2]);
            //显示停止下注
            stopBet.SetActive(true);
            StartCoroutine(HideStopBet());
        }
        #endregion  停止下注广播

        #region  通知掷骰子广播
        else if (TempMsgID == MsgId.PaiThrowDiceBroadcast)//通知掷骰子
        {
            Pb.PaiThrowDiceBroadcast newpb = Pb.PaiThrowDiceBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log("通知掷骰子");
            if (xtj.isBanker == true)
            {
                SetSaizi.SetActive(true);
            }
            GameObject setShaiZi = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.SetSaiZiPanel));
            setShaiZi.transform.localPosition = new Vector3(-35, 8, 0);
        }
        #endregion  通知掷骰子广播

        #region  掷骰子响应
        //掷骰子响应
        else if (TempMsgID == MsgId.PaiThrowDiceResponse)
        {
            Pb.PaiThrowDiceResponse newpb = Pb.PaiThrowDiceResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == (int)STATUS.Success)
            {

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject msg = NGUITools.AddChild(Root, (GameObject)Resources.Load("LogMsg"));
            }
        }
        #endregion  掷骰子响应

        #region  掷骰子广播
        else if (TempMsgID == MsgId.PaiThrowDiceResultBroadcast)//開始擲骰子操作
        {
            Pb.PaiThrowDiceResultBroadcast newpb = Pb.PaiThrowDiceResultBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            SetSaizi.SetActive(false);
            GameObject dice = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJPrafabPath.Shaizi));
            DiceModel diceModel = dice.GetComponent<DiceModel>();
            diceModel.diceAniObj.SetActive(true);
            diceSum = newpb.Points[0] + newpb.Points[1];
            //播放掷骰子音效
            SoundModel.PlaySound(effectBgList[5]);
            StartCoroutine(DiceAnimation(diceModel, newpb.Points.ToList()));

        }
        #endregion  掷骰子广播

        #region  发牌广播
        else if (TempMsgID == MsgId.PaiDealCardBroadcast)//进行发牌操作
        {
            Pb.PaiDealCardBroadcast newpb = Pb.PaiDealCardBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            //销毁筛子
            GameObject dice = GameObject.Find("UI Root/Shaizi");
            if (dice != null)
            {
                Destroy(dice);
            }
            //计算发牌顺序
            SortDealCards();
            //发牌
            StartCoroutine(CloneCards(newpb));

        }
        #endregion  发牌广播

        #region  一局结束后的广播
        else if (TempMsgID == MsgId.PaiGameOverBroadcast)//一局结束后的广播
        {

        }
        #endregion  一局结束后的广播
        //房间中所有玩家列表
        else if (TempMsgID == MsgId.PaiAllPlayersResponse)
        {
            Pb.PaiAllPlayersResponse newpb = Pb.PaiAllPlayersResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //加载所有玩家面板
            GameObject playerPanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.PlayersList));
            PlayerListPanel playerListPanel = playerPanel.GetComponent<PlayerListPanel>();
            playerListPanel.playerList = newpb.Players.ToList();
        }
        //发牌历史记录
        else if (TempMsgID == MsgId.PaiCardHistoryResponse)
        {
            Pb.PaiCardHistoryResponse newpb = Pb.PaiCardHistoryResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            GameObject history = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.Histrory));
            HistoryPanel historyPanel = history.GetComponent<HistoryPanel>();
            historyPanel.cardRecordList = newpb.Cards.ToList();
        }
        //聊天
        else if (TempMsgID == MsgId.PaiRoomChatBroadcast)
        {
            Pb.PaiRoomChatBroadcast newpb = Pb.PaiRoomChatBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            StartCoroutine(TextFaceChat(newpb));
        }
        //网络异常
        else if (TempMsgID == MsgId.NetWorkAbnormalMessage)
        {
            GameObject NetWorkAbnormal = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("NetWorkAbnormal")));
        }
        //存钱（服务器返回）
        else if (TempMsgID == MsgId.Bag2BankResponse)
        {
            Bag2BankResponse newpb = Bag2BankResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (BankPanel && bankModel)
                {
                    print("进入了" + newpb.BankCointCount);
                    user.bankCoinCount += bankModel.StrToInt(bankModel.getInLabel.text);
                    bankModel.sumLabel.text = "已存入：" + user.bankCoinCount + "万金币";
                    bankModel.getInLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "存入成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //取钱（服务器返回）
        else if (TempMsgID == MsgId.Bank2BagResponse)
        {
            Bank2BagResponse newpb = Bank2BagResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (bankPanel && bankModel)
                {
                    user.bankCoinCount -= bankModel.StrToInt(bankModel.getOutLabel.text);
                    isHaveCoin = bankModel.StrToInt(bankModel.getOutLabel.text);
                    bankModel.sumLabel.text = "已取出：" + isHaveCoin + "万金币";
                    bankModel.getOutLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "取出成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }

    }

    /// <summary>
    /// 加载玩家信息
    /// </summary>
    void LoadUser()
    {
        //显示房间内玩家的个数
        playersNum.text = xtj.playersNum.ToString();
        //显示自己的信息
        xtjMyOwnInfo.nameLabel.text = user.nickname;
        xtjMyOwnInfo.goldLabel.text = user.ReturnMoneyForLong(long.Parse(user.coinCount));

        Debug.Log(xtj.playersList.Count);
        //显示座上玩家的信息
        for (int i = 0; i < xtj.playersList.Count; i++)
        {
            xtjUsers[i].goldLabel.text = user.ReturnMoneyForLong(xtj.playersList[i].Coin);
            xtjUsers[i].goldLabel.transform.parent.gameObject.SetActive(true);
            xtjUsers[i].chairLabel.gameObject.SetActive(false);
            xtjUsers[i].uid = xtj.playersList[i].Id;
            if (xtj.playersList[i].AvatarUrl != "")
            {
                WXAvatarManager._instance.GetWxAvatar(xtj.playersList[i].Id, xtjUsers[i].wxAvatar, xtj.playersList[i].AvatarUrl);
                xtjUsers[i].wxAvatar.gameObject.SetActive(true);
            }
            else
            {
                xtjUsers[i].avatar.spriteName = xtj.playersList[i].AvatarId.ToString();
                xtjUsers[i].avatar.gameObject.SetActive(true);
            }
        }

        //显示庄家的信息
        if (xtj.bankerId != 0)
        {
            xtjBankerInfo.nameLabel.text = xtj.bankerInfo.Nickname;
            if (xtj.bankerInfo.AvatarUrl != "")
            {
                WXAvatarManager._instance.GetWxAvatar(xtj.bankerId, xtjBankerInfo.wxAvatar, xtj.bankerInfo.AvatarUrl);
                xtjBankerInfo.wxAvatar.gameObject.SetActive(true);
            }
            else
            {
                xtjBankerInfo.avatar.spriteName = xtj.bankerInfo.AvatarId.ToString();
            }
            xtjBankerInfo.goldLabel.text = user.ReturnMoneyForLong(xtj.bankerInfo.Coin);
        }
        else
        {
            xtjBankerInfo.nameLabel.text = "系统坐庄";
            if (xtj.bankerInfo.AvatarUrl != "")
            {
                WXAvatarManager._instance.GetWxAvatar(xtj.bankerId, xtjBankerInfo.wxAvatar, xtj.bankerInfo.AvatarUrl);
                xtjBankerInfo.wxAvatar.gameObject.SetActive(true);
            }
            else
            {
                xtjBankerInfo.avatar.spriteName = "avatar";
            }
            xtjBankerInfo.goldLabel.text = user.ReturnMoneyForLong(xtj.systemCoin);
        }

        xtjBankerInfo.uid = xtj.bankerId;
        xtjBankerInfo.gameObject.SetActive(true);



        //显示各个方位的总筹码数
        for (int i = 0; i < xtj.newpb.AllChips.Count; i++)
        {
            KeyValuePair<int, PaiInt64Array> keyValue = xtj.newpb.AllChips.ElementAt(i);
            long sum = 0;
            for (int j = 0; j < keyValue.Value.Value.Count; j++)
            {
                ReconnectCloneChip(keyValue.Value.Value.Count, keyValue.Value.Value[j], keyValue.Key);
                sum += keyValue.Value.Value[j];
            }
            poolChipsCountLabels[keyValue.Key - 1].text = sum.ToString();
        }
        //显示自己在各个方位下的筹码数
        for (int i = 0; i < xtj.newpb.SelfChips.Count; i++)
        {
            KeyValuePair<int, PaiInt64Array> keyValue = xtj.newpb.SelfChips.ElementAt(i);
            long ownSum = 0;
            for (int j = 0; j < keyValue.Value.Value.Count; j++)
            {
                ownSum += keyValue.Value.Value[j];
            }
            ownChipsCountLabels[keyValue.Key - 1].text = ownSum.ToString();
        }

        if (xtj.newpb.CardMap.Count > 0)
        {
            GameObject cardsPanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJPrafabPath.CardsPanel));
            //显示发的牌
            for (int i = 0; i < xtj.newpb.CardMap.Count; i++)
            {
                KeyValuePair<int, PaiCardGroup> keyValue = xtj.newpb.CardMap.ElementAt(i);
                GameObject cardItem = Instantiate(cardsPre);
                cardItem.transform.parent = cardsPanel.transform;
                cardItem.transform.localScale = Vector3.one;
                cardItem.transform.localPosition = new Vector3(0, 296, 0);
                Cards cards = cardItem.GetComponent<Cards>();
                //蔡轩改
                if (keyValue.Key == 1)
                {
                    cardItem.transform.localPosition = ShunMen.transform.localPosition;
                }
                else if (keyValue.Key == 2)//庄家牌
                {
                    cardItem.transform.localPosition = Tang.transform.localPosition;

                }
                else if (keyValue.Key == 3)
                {
                    cardItem.transform.localPosition = Daomen.transform.localPosition;
                }
                else if (keyValue.Key == 5)
                {
                    cardItem.transform.localPosition = Tianmen.transform.localPosition;
                }
                else if (keyValue.Key == 6)
                {
                    cardItem.transform.localPosition = ShunJiao.transform.localPosition;
                }
                cards.destination = cardItem.transform.localPosition;
                cards.ShowCards(keyValue.Value.Cards.ToList(), keyValue.Value.Form);
            }
        }

        //显示一局结束后的分数和金币数
        if (xtj.newpb.CoinMap.Count > 0)
        {
            GameObject gameOver = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.GameOver));
            XTJ100GameOver xtj100GameOver = gameOver.GetComponent<XTJ100GameOver>();
            for (int i = 0; i < xtj.newpb.CoinMap.Count; i++)
            {
                KeyValuePair<int, PaiInt64Array> keyValue = xtj.newpb.CoinMap.ElementAt(i);
                for (int j = 0; j < xtj100GameOver.ScoreFathers.Count; j++)
                {
                    //显示自己的得分
                    if (keyValue.Key == int.Parse(EginUser.Instance.Uid))
                    {
                        xtj100GameOver.ShowScore(keyValue.Value.Value[0], xtj100GameOver.ScoreSprites[4], xtj100GameOver.ScoreFathers[4], xtj100GameOver.JiaJians[4]);
                        //显示自己剩余的金币数
                        xtjMyOwnInfo.goldLabel.text = EginUser.Instance.ReturnMoneyForLong(keyValue.Value.Value[1]);
                        //更新自己的金币数
                        EginUser.Instance.coinCount = keyValue.Value.Value[1].ToString();
                    }
                    else if (keyValue.Key == xtj.bankerId)
                    {
                        xtj100GameOver.ShowScore(keyValue.Value.Value[0], xtj100GameOver.ScoreSprites[5], xtj100GameOver.ScoreFathers[5], xtj100GameOver.JiaJians[5]);
                        //更新庄家的金币数
                        xtjBankerInfo.goldLabel.text = EginUser.Instance.ReturnMoneyForLong(keyValue.Value.Value[1]);
                    }
                    else
                    {
                        for (int k = 0; k < xtjUsers.Count; i++)
                        {
                            if (keyValue.Key == xtjUsers[k].uid)
                            {
                                xtj100GameOver.ShowScore(keyValue.Value.Value[0], xtj100GameOver.ScoreSprites[k], xtj100GameOver.ScoreFathers[k], xtj100GameOver.JiaJians[k]);
                                //更新上座的人的金币数
                                xtjUsers[k].goldLabel.text = EginUser.Instance.ReturnMoneyForLong(keyValue.Value.Value[1]);
                            }
                        }
                    }
                }
            }
        }
    }

    IEnumerator DiceAnimation(DiceModel diceModel, List<int> points)
    {
        yield return new WaitForSeconds(1.5f);
        diceModel.diceAniObj.SetActive(false);
        diceModel.dice1.spriteName = "shaizi" + points[0].ToString();
        diceModel.dice2.spriteName = "shaizi" + points[1].ToString();
        diceModel.dice1.gameObject.SetActive(true);
        diceModel.dice2.gameObject.SetActive(true);
    }

    /// <summary>
    /// 克隆筹码
    /// </summary>
    public void CloneChips(int id, int direction, long chipCoin)
    {
        Vector3 tempPos = new Vector3();
        GameObject chip = Instantiate(ChipPre);
        chip.transform.SetParent(chipParent.transform);
        chip.transform.localPosition = ChipPre.transform.localPosition;
        //Debug.Log("筹码图片名称：" + (chipCoin / 10000));
        //chip.GetComponent<UISprite>().spriteName =  (chipCoin / 10000).ToString();
        Debug.Log("筹码图片名称：" + chipCoin);
        chip.GetComponent<UISprite>().spriteName = chipCoin.ToString();
        chip.GetComponent<UISprite>().MakePixelPerfect();
        chip.transform.localScale = new Vector3(0.7f, 0.7f, 1);
        //确定是谁下的注        
        //for (int i = 0; i < xtj.playersList.Count; i++)
        //{
        //    if (xtjUsers[i].uid == id)
        //    {
        //        chip.transform.localPosition = xtjUsers[i].transform.localPosition;
        //    }
        //}


        //确定移动的终点
        if (direction == 1)
        {
            tempPos = new Vector3(Random.Range(-393, -246), Random.Range(-21, 97), 0);
        }
        else if (direction == 2)
        {
            Debug.LogError("错误选项2");
            tempPos = new Vector3(Random.Range(-120, 80), Random.Range(60, 105), 0);
        }
        else if (direction == 3)
        {
            tempPos = new Vector3(Random.Range(-175, -36), Random.Range(-25, 93), 0);
        }
        else if (direction == 4)
        {
            Debug.LogError("错误选项");
            tempPos = new Vector3(Random.Range(175, 320), Random.Range(-170, -115), 0);
        }
        else if (direction == 5)
        {
            tempPos = new Vector3(Random.Range(37, 178), Random.Range(-25, 93), 0);
        }
        else if (direction == 6)
        {
            tempPos = new Vector3(Random.Range(248, 387), Random.Range(-25, 93), 0);
        }
        ChipsMove chipsMove = chip.GetComponent<ChipsMove>();
        chipsMove.destination = tempPos;
        chip.SetActive(true);

    }

    /// <summary>
    /// 确定发牌的顺序
    /// </summary>
    /// <returns></returns>
    public void SortDealCards()
    {
        //蔡轩改
        int num = diceSum % 5;
        if (num == 0)
        {
            dealCardsPosDic.Add(2, Tang);
            dealCardsPosDic.Add(1, ShunMen);
            dealCardsPosDic.Add(3, Daomen);
            dealCardsPosDic.Add(5, Tianmen);
            dealCardsPosDic.Add(6, ShunJiao);
        }
        else if (num == 1)
        {
            dealCardsPosDic.Add(1, ShunMen);
            dealCardsPosDic.Add(3, Daomen);
            dealCardsPosDic.Add(5, Tianmen);
            dealCardsPosDic.Add(6, ShunJiao);
            dealCardsPosDic.Add(2, Tang);
        }
        else if (num == 2)
        {

            dealCardsPosDic.Add(3, Daomen);
            dealCardsPosDic.Add(5, Tianmen);
            dealCardsPosDic.Add(6, ShunJiao);
            dealCardsPosDic.Add(2, Tang);
            dealCardsPosDic.Add(1, ShunMen);
        }
        else if (num == 3)
        {

            dealCardsPosDic.Add(5, Tianmen);
            dealCardsPosDic.Add(6, ShunJiao);
            dealCardsPosDic.Add(2, Tang);
            dealCardsPosDic.Add(1, ShunMen);
            dealCardsPosDic.Add(3, Daomen);
        }
        else if (num == 4)
        {

            dealCardsPosDic.Add(6, ShunJiao);
            dealCardsPosDic.Add(2, Tang);
            dealCardsPosDic.Add(1, ShunMen);
            dealCardsPosDic.Add(3, Daomen);
            dealCardsPosDic.Add(5, Tianmen);
        }
    }

    /// <summary>
    /// 克隆牌
    /// </summary>
    /// <param name="newpb"></param>
    /// <returns></returns>
    IEnumerator CloneCards(PaiDealCardBroadcast newpb)
    {
        dealCardsDic.Clear();
        //播放开始发牌音效
        SoundModel.PlaySound(effectBgList[3]);
        GameObject cardsPanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJPrafabPath.CardsPanel));
        for (int i = 0; i < dealCardsPosDic.Count; i++)
        {
            GameObject cardsObj = Instantiate(cardsPre);
            cardsObj.transform.SetParent(cardsPanel.transform);

            cardsObj.transform.localScale = Vector3.one;
            cardsObj.transform.localPosition = new Vector3(0, 296, 0);
            Cards cards = cardsObj.GetComponent<Cards>();
            KeyValuePair<int, GameObject> element = dealCardsPosDic.ElementAt(i);
            cards.destination = element.Value.transform.localPosition;
            dealCardsDic.Add(element.Key, cardsObj);
            yield return new WaitForSeconds(0.5f);
        }

        StartCoroutine(ShowCards(newpb));
    }

    /// <summary>
    /// 展示牌
    /// </summary>
    /// <param name="newpb"></param>
    /// <returns></returns>
    IEnumerator ShowCards(PaiDealCardBroadcast newpb)
    {
        GameObject showCardTime = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.ShowCards));
        showCardTime.transform.localPosition = new Vector3(-35, 8, 0);
        yield return new WaitForSeconds(2f);
        for (int i = 0; i < dealCardsPosDic.Count; i++)
        {
            KeyValuePair<int, GameObject> element = dealCardsDic.ElementAt(i);
            foreach (KeyValuePair<int, PaiCardGroup> keyValue in newpb.CardMap)
            {
                if (element.Key == keyValue.Key)
                {
                    Cards cards = element.Value.GetComponent<Cards>();
                    cards.ShowCards(newpb.CardMap[keyValue.Key].Cards.ToList(), newpb.CardMap[keyValue.Key].Form);
                }
            }
            yield return new WaitForSeconds(0.5f);

        }

        //加载游戏结束面板
        GameObject gameOverPanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJ100PrefabPath.GameOver));
        XTJ100GameOver gameOver = gameOverPanel.GetComponent<XTJ100GameOver>();
        gameOver.newpb = newpb;
    }


    /// <summary>
    /// 恢复初始状态
    /// </summary>
    public void RecoverInit()
    {
        //玩家恢复
        //for (int i = 0; i < xtjUsers.Count; i++)
        //{
        //    //xtjUsers[i].readyStatus.SetActive(false);
        //    //xtjUsers[i].QiangZhuangStatus.SetActive(false);
        //    //xtjUsers[i].bankerIcon.SetActive(false);
        //    xtjUsers[i].avatar.gameObject.SetActive(false);
        //    xtjUsers[i].wxAvatar.gameObject.SetActive(false);
        //    xtjUsers[i].goldLabel.transform.parent.gameObject.SetActive(false);
        //    xtjUsers[i].chairLabel.gameObject.SetActive(true);
        //}

        //筹码销毁
        for (int i = 0; i < chipParent.transform.childCount; i++)
        {
            Destroy(chipParent.transform.GetChild(i).gameObject);
        }
        //筹码数置空
        for (int i = 0; i < poolChipsCountLabels.Count; i++)
        {
            poolChipsCountLabels[i].text = "";
            ownChipsCountLabels[i].text = "";
            ownChipsCountList[i] = 0;
        }

        xtj.bankerId = 0;
        xtj.isReady = false;
        dealCardsDic.Clear();
        dealCardsPosDic.Clear();
    }

    /// <summary>
    /// 隐藏停止下注显示框
    /// </summary>
    /// <returns></returns>
    IEnumerator HideStopBet()
    {
        yield return new WaitForSeconds(1f);
        stopBet.SetActive(false);
    }


    /// <summary>
    /// 重连克隆筹码
    /// </summary>
    void ReconnectCloneChip(int count, long spriteNameId, int direction)
    {
        Vector3 tempPos = new Vector3();
        //for (int i = 0; i < count;i++ )
        {
            GameObject chip = Instantiate(ChipPre);
            chip.transform.parent = chipParent.transform;

            Debug.Log("筹码图片名称：" + spriteNameId);
            chip.GetComponent<UISprite>().spriteName = spriteNameId.ToString();
            chip.GetComponent<UISprite>().MakePixelPerfect();
            chip.transform.localScale = new Vector3(0.7f, 0.7f, 1);
            //确定移动的终点
            if (direction == 1)
            {
                tempPos = new Vector3(Random.Range(-393, -246), Random.Range(-21, 97), 0);
            }
            else if (direction == 2)
            {
                Debug.LogError("错误选项2");
                tempPos = new Vector3(Random.Range(-120, 80), Random.Range(60, 105), 0);
            }
            else if (direction == 3)
            {
                tempPos = new Vector3(Random.Range(-175, -36), Random.Range(-25, 93), 0);
            }
            else if (direction == 4)
            {
                Debug.LogError("错误选项");
                tempPos = new Vector3(Random.Range(175, 320), Random.Range(-170, -115), 0);
            }
            else if (direction == 5)
            {
                tempPos = new Vector3(Random.Range(37, 178), Random.Range(-25, 93), 0);
            }
            else if (direction == 6)
            {
                tempPos = new Vector3(Random.Range(248, 387), Random.Range(-25, 93), 0);
            }
            ChipsMove chipsMove = chip.GetComponent<ChipsMove>();
            chipsMove.destination = tempPos;
            chip.SetActive(true);
        }
    }

    /// <summary>
    /// 聊天
    /// </summary>
    /// <param name="newpb"></param>
    /// <returns></returns>
    IEnumerator TextFaceChat(PaiRoomChatBroadcast newpb)
    {
        chatAvatar.spriteName = newpb.AvatarId.ToString();
        chatItem.SetActive(true);
        if (newpb.MsgType == RoomChatType.TextId)
        {
            text.text = xtjText[int.Parse(newpb.Content) - 1];
            text.gameObject.SetActive(true);
            face.gameObject.SetActive(false);
        }
        else if (newpb.MsgType == RoomChatType.MovieClip)
        {
            face.gameObject.SetActive(true);
            text.gameObject.SetActive(false);
            face.spriteName = newpb.Content;
            Debug.Log("表情名字是：" + newpb.Content);
        }
        yield return new WaitForSeconds(1.5f);
        chatItem.SetActive(false);

    }
}
